This article reprinted address : http://www.cnblogs.com/zuoxiaolong/p/computer15.htmlIntroductionIn the previous chapter, we have introduced the basic part of assembly language, including the data format, register, and how to identify the number of operands, and then we should get to know the various instructions in assembly language. Most of these instructions are very simple, but it is really magical to combine them to simulate any effect we want in our program. Data transfer InstructionsThe
Will be uploaded I wrote a new book, "Write Your Own CPU" (not yet published), today is the 23rd, I try to four weekly6.4Test ProgramThis section will verify that the mobile operation instructions added to the Openmips processor are implemented correctly with a test program as follows, corresponding to the book with the CD code\chapter6\asmtest The Inst_rom in the directory . S file. . org 0x0.set Noat.global _start_start://Give register $, $, $, $4 assign initial value lui $1,0x0000 # $ = 0x0
compiler will equate this instruction with" movw % ax, %BX ". Similarly, the command "mov $4, % EBX" is equivalent to the command "movl $4, % EBX", and "Push % Al" is equivalentIn "pushb % Al ". The compiler reports an error for an instruction that does not specify the length of an operand but cannot be guessed by the compiler,For example, the command "Push $4 ".6. symbol extension and zero extension commandsThe vast majority of att Assembly commands for 80386 are the same as Intel-formatted As
access a memory location based on a valid address3.4.2 Data Transfer InstructionsThe routing instruction is divided into the instruction class: The instruction in a class executes the same operation, except that the operands are of different sizes.The Mov class's instruction copies the value of the source operand to the destination operandBoth the Movs and Movz directives replicate a smaller source data to a larger data location, with the sign bit ex
) Si0x0804845e 5 char c[] = "1234567890";= 0x804845e movw $0x3039,0x29 (%ESP)(gdb) Print $esp$ = (void *) 0xbffff2300x08048465 5 char c[] = "1234567890";= 0x8048465 movb $0x0,0x2b (%ESP)(gdb) Print $esp$4 = (void *) 0xbffff230MOVZBL:In the/t syntax, the symbol extension and the 0 extension directives are in the format. The basic section "Movs" and "Movz" (the corresponding Intel syntax for movsx and movzx, The MOVZX is a zero extension, which is a hi
Will be uploaded I wrote a new book, "Write Your Own CPU" (not yet published), today is the 21st, I try to four weekly6.2The idea of moving operation instruction Realization6.2.1Implementation IdeasThis6The move instructions can be divided into two categories: one is not involved in special registersHI,LOthe instructions, includingMOVN,MovzAnd the other involves special registers.HI,LOthe instructions, includingMfhi,Mflo,Mthi,Mtlo. The first class is very good realization, the basic idea and the
Instruction of the operand has two suffixes: One specifying the length of the source operand and the otherSpecifies the length of the target operand. Att's symbolic extension command is "movs", and the zero extension command is "movz" (correspondingThe intel commands are "movsx" and "movzx "). Therefore, "movsbl % Al, % edX" indicatesByte data is extended by byte to long characters, and the calculation result is stored in the register EDX. The follow
, % xmm8
Again, the addressing representation between att and Intel syntax is also different:
(Intel) sub eax, [EBX + ECx * 4 h-20 h] (att) subl-0x20 (% EBX, % ECx, 0x4), % eax
The above indicates that you do not need to add the $ symbol before the scaling factor and the number of offsets.
This can be summarized as follows: If Intel's addressing mode is [
Finally, att and Intel have different instructions:
In intel command representation, movsx is used for signed extended mov commands, while
values. Can be used to record certain file states or to hold temporary values.
Stripe Register: Holds state information for the most recently executed arithmetic or logical instruction.
Floating-point registers: A set of vector registers can hold one or more certificates or floating-point values.General purpose register of the processor
The central processing unit (CPU) of the x86-64 contains a set of 16 common purpose registers that store 64-bit valuesAssembly Instructions
MOV
) = Imm + R[eb] + r[ei]*sP114:mov equivalent to the assignment "=" of the C language, paying attention to the direction in the ATT format,Also note that you cannot direct MOV from the memory address to another memory address, to use the register to relay a bit. Can distinguish Mov,movs,movz, master Push,popp115/p116: Stack frame and push pop; Note that the address of the top element of the stack is the lowest of all the element addresses in the stack.
. Operand indicator Type: Immediate count, register, register2. Data transfer Instructions
instruction
Effect
Description
mov s,d /td>
s
Transfer
Movb MOVW Movl
Transfer bytes Routing Word Transfer double character
movs s,d
d
Transfer byte of symbol extension
movz s,d /td>
d
a single operation of the MIPS CPU can load or store 1 to 8 bytes of data. The multiplication result registers are interlocked (interlocked) Because the result of the multiplication is not enough to allow the next instruction to automatically get the result. Attempting to read the result register before the multiplication operation completes causes the CPU to stop running until it is complete. One of the goals of the MIPS architecture, compared to some of the simpler RISC architectures, is that
message from Ebp+c, deposited it in eax, and then started the switch process, and he kept comparing these to determine which messageOK, we know that pressing the button will produce Wm_commad (111) message, then when we see CMP eax,111,je jumping, we are close to the target, tracking JE to the destination, we will be surprised, how to compare Ah, this is because there are many buttons, each press will produce a WM _commad (111), then we need to decide again which button?We used WPARAM's low fou
Character Input is supported.
6. Supports comments, such as line comments/And block comments /**/
Ii. Low-level code writing of the j2_snake script engine:
1. The syntax is similar to the 8086 assembly, but it is much simpler than it. There are 33 virtual commands available, you can also define a method to demonstrate a complete addition function and the function call Semicolon is a line annotator ):
MyAdd ()
{
Paramy; function parameter y
Paramx; function parameter x
Addx, y; Add
: The MOVZ instruction stores a shorter byte value into a long-byte storage unit with a high-level 0 padding. The directive can have B (byte), W (word), L (long) three suffixes, representing single-byte, two-byte, and four-byte, respectively. For example Movzbl 0x804a019,%eax said to the address 0x804a019 place a byte into the EAX register, and the EAX register is four bytes, the three bytes with 0 padding, and the next instruction mov%al, The Al reg
,movl respectively: transmit bytes, transmit word, transfer double word2, MOVSBW,MOVSBL,MOVSWL, will do the symbol extension of the byte to the word, will do the symbol extension of the byte to the word, will do the symbol extension of the word to the word3, Movzbw,movzbl,movzwl,pushls,popl D, will do 0 extended ~~~~PUSHL and POPL instructions to do the following explanations:PUSHL S ( double word Press stack ):r[%esp]m[r[%esp]]So: The PUSHL instruction is equivalent to a sub address and a MOVL
remaining 0x44c, do not think EAX is 32 bits will not occur overflow.9. Master valid Address calculation method IMM (eb,ei,s) = Imm + R[eb] + r[ei]*sThe MOV is equivalent to the C language Assignment "=", note the direction in the ATT format, also note that you can not from the memory address of the direct MOV to another memory address, to use the register to relay a bit. Can distinguish Mov,movs,movz, master Push,pop11. Stack frame and push pop; Not
+r[eb]+r[ei]*s. IMM is the immediate number offset; EB is the base register; EI is the variable address register; s is a scale factor. Such as:1) ea--operation value: R[ea]2) (Ea)--Operation value: M (R[ea])3) Imm (Ea)--Operation value: M (Imm+r[ea])A 14.mov statement means that the value is "moved" from the source operand to the destination operand (the former, the latter in the previous), and equivalent to the assignment. In IA32, it is stipulated that the memory address cannot be directly mov
arrays, esp EBP is used to manipulate stack frames. For registers, especially the Eax,ebx,ecx,edx in the General register, we should understand that the ah,al of the ax,8 bits of the 32-bit eax,16 bits are independent, and we illustrate p113 by the following example: Combining tables, in-depth understanding of the various addressing modes; understanding three types of operands: immediate , register, memory, master effective Address calculation method Imm (eb,ei,s) = Imm + R[eb] + R[ei]*sp114:mo
operand, and "B" indicates byte.(One byte); "w" indicates word (2, in bytes); "l" indicates long (4, in bytes ).When Processing Memory operands in INTEL, there are similar syntaxes such:Byte ptr, word ptr, and dword ptr.Example:INTELAT TMov al, blmovb % bl, % alMov ax, bxmovw % bx, % axMov eax, dword ptr [ebx] movl (% ebx), % eaxIn the ATT assembly instruction, the operand extension instruction has two suffixes: One specifying the length of the source operand and the other specifying the lengt
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.